<template>
  <el-container class="main_con">
    <div class="filter_con ds_block">
      <div class="button_area">
        <el-button v-has size="small" type="primary" @click="addHandle">新增直播间</el-button>
        <el-button v-has size="small" type="primary" @click="syncHandle">同步直播间</el-button>
      </div>
      <div class="filter_area">
        <el-input size="small" v-model="params.name" class="serach_input mr_15 mt_15" placeholder="检索标题,微信号,主播昵称"></el-input>
        <label class="mr_15 ml_15">主播间状态</label>
        <el-select clearable size="small" v-model="params.status" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <label class="mr_15 ml_15">直播时间</label>
        <date-picker size="small" @change="gettime" class="mr_15 mt_15"></date-picker>
        <el-button size="small" @click="search">搜索</el-button>
      </div>
    </div>
    <div class="list_con">
      <el-table @selection-change="SelectHadnle" :data="list" element-loading-text fit highlight-current-row class="main-loading">
        <el-table-column prop="id" label="直播间ID"></el-table-column>
        <el-table-column prop="title" label="直播间名称"></el-table-column>
        <el-table-column prop="anchor_name" label="主播昵称"></el-table-column>
        <el-table-column prop="anchor_wechat" label="主播微信号"></el-table-column>
        <el-table-column prop="mobile" label="直播时间" width="180px">
          <template slot-scope="scope">
            <span>{{ scope.row.start_time }}</span>
            <br />
            <span>{{ scope.row.end_time }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status | statustxt }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="官方收录">
          <template slot-scope="scope">
            <el-switch
              @change="changef($event, scope.row)"
              :active-value="1"
              :inactive-value="0"
              v-model="scope.row.is_feeds_public"
              active-text="开启"
              inactive-text="关闭"
            ></el-switch>
          </template>
        </el-table-column>
        <!--    <el-table-column prop="status" label="直播评论">
           <template slot-scope="scope">
             <el-switch
               @change="changecomment($event, scope.row)"
               :active-value="0"
               :inactive-value="1"
               v-model="scope.row.close_comment"
               active-text="开启"
               inactive-text="关闭"
             ></el-switch>
           </template>
            </el-table-column> -->

        <el-table-column label="操作" width="180px">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status == 102" v-has type="text" @click="EditHandle(scope.row.id)">编辑</el-button>
            <el-button v-has type="text" @click="operateHandle(scope.row.id)">运营</el-button>
            <!-- <el-button v-has :disabled="!!scope.row.close_time" type="text" @click="EnableHandle(scope.row.id)">停止</el-button> -->
            <el-button v-has type="text" @click="handleClose(scope.row.room_id)">删除</el-button>
            <el-button v-has v-if="scope.row.status == 102||scope.row.status == 101" type="text" @click="getQrcode(scope.row.room_id)">分享码</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer">
        <!--  <el-button size="medium">批量删除
        </el-button>-->
        <el-pagination
          @current-change="ChangeCurrent"
          class="pages"
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="params.size"
          :page-count="params.page"
          hide-on-single-page
        ></el-pagination>
      </div>
    </div>
    <!-- <el-drawer class="w_80" title="编辑管理员" :visible.sync="drawer" :direction="direction">
      <edituser @on-close="beClose" :uid='user_id' :user_type="user_type"></edituser>
    </el-drawer>-->
    <el-dialog title="直播间分享码" :visible.sync="showQrcode" width="500px" class="dialog_box">
      <div class="u-flex" style="width:100%;justify-content: center;"><img style="width: 200px;" :src="Qrcode" /></div>
    </el-dialog>
  </el-container>
</template>

<script>
import {mapGetters} from 'vuex';
import {getliveroomlist, syncRoom, delliver, updateFeedPublic, getQrcode} from '@/api/mall/liver';
import DatePicker from '@/components/DatePicker/index';
import {fitter_keyword} from '@/utils/index';
export default {
  data() {
    return {
      showQrcode: false,
      Qrcode: '',
      params: {
        name: '',
        status: '',
        start_time: '',
        end_time: '',
        page: 1,
        size: 10
      },
      paramsdf: {},
      options: [
        {
          value: 101,
          label: '直播中'
        },
        {
          value: 102,
          label: '未开始'
        },
        {
          value: 103,
          label: '已结束'
        },
        {
          value: 104,
          label: '禁播'
        },
        {
          value: 105,
          label: '暂停'
        },
        {
          value: 106,
          label: '异常'
        },
        {
          value: 107,
          label: '已过期'
        }
      ],

      total: 0,
      listLoading: true,
      list: [],
      drawer: false,
      direction: 'rtl',
      user_id: '',
      user_type: 'add',
      selectionData: [],
      url: ''
    };
  },
  components: {
    DatePicker
  },
  computed: {
    ...mapGetters(['allroleslist'])
  },
  mounted() {
    this.getlist();
  },
  filters: {
    statustxt(status) {
      switch (status) {
        case 101:
          return '直播中';
          break;
        case 102:
          return '未开始';
          break;
        case 103:
          return '已结束';
          break;
        case 104:
          return '禁播';
          break;
        case 105:
          return '暂停';
          break;
        case 106:
          return '异常';
          break;
        case 107:
          return '已过期';
          break;
        default:
          return '-';
          break;
      }
    }
  },
  methods: {
    getQrcode(id) {
      this.Qrcode = '';
      let data = {
        id: id
      };
      getQrcode(data).then(res => {
        this.Qrcode = res.msg.cdnUrl;
        this.showQrcode = true;
      });
    },
    changecomment() {
      console.log(a, b);
      let data = {
        status: a,
        id: b.room_id
      };
      // updateFeedPublic(data).then(res => {
      //   this.getlist();
      // });
    },
    changef(a, b) {
      console.log(a, b);
      let data = {
        status: a,
        id: b.room_id
      };
      updateFeedPublic(data).then(res => {
        this.getlist();
      });
    },
    doCopy(data) {
      this.$copyText(data).then(
        res => {
          //this.$alert('复制成功');
          this.$message({
            message: '复制成功',
            type: 'success',
            duration: 2000
          });
          // data.visible = false;
        },
        error => {
          this.$alert('无法复制');
        }
      );
    },
    search() {
      this.paramsdf = fitter_keyword(this.params);
      this.getlist();
    },
    //启用，禁用
    EnableHandle(id) {
      let _this = this;
      this.$confirm('确认停止当前活动？')
        .then(_ => {
          let params = {id: id};
          stopgroup(params).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //选择
    SelectHadnle(selection) {
      this.selectionData = selection;
    },
    //删除
    handleClose(id) {
      let _this = this;
      this.$confirm('确认删除？')
        .then(_ => {
          let data = {
            id: id
          };
          delliver(data).then(res => {
            this.$message.success('删除成功');
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //新增
    addHandle() {
      this.$router.push('/liver/item');
    },
    //编辑
    EditHandle(id) {
      this.$router.push({path: '/liver/item', query: {id: id}});
    },
    operateHandle(id) {
      this.$router.push({path: '/liver/operate', query: {id: id}});
    },
    //编辑完成
    beClose() {
      (this.drawer = false), this.getlist();
    },
    //获取列表
    getlist() {
      this.listLoading = true;
      let data = fitter_keyword(this.params);
      getliveroomlist(data).then(res => {
        var jsondata = res.msg;
        this.list = jsondata.data;
        this.total = jsondata.total;
        // this.list = response.data.items
        this.listLoading = false;
      });
    },
    //获取时间
    gettime(value) {
      this.params.start_time = value[0];
      this.params.end_time = value[1];
    },
    //切换页码
    ChangeCurrent(page) {
      this.params.page = page;
      this.getlist();
    },
    syncHandle() {
      syncRoom({}).then(res => {
        this.getlist();
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.login_url {
  padding: 8px 16px;
  background-color: #f4f4f5;
  color: #909399;
  box-sizing: border-box;
  border-radius: 4px;
  display: flex;
  align-items: center;
  font-size: 14px;
  p {
    margin: 0;
    margin-right: 10px;
  }
  .el-button {
    padding: 0;
  }
}
</style>
